<?

$header = new SectionTemplate;
$header->file = "header.php";
$footer = new SectionTemplate;
$footer->file = "footer.php";

$search = new SectionTemplate;
$search->file = "shows_search.php";

include_class('shows');
include_class('tours');
include_class('m2');
include_class('tours');
include_class('band_members');


$view = '';
if ($_GET['id']) {
	$t = Tour::get($_GET['id']);
	if ($_GET['media_instance_id'] > 0) { 
		$mi = MediaInstance::get($_GET['media_instance_id']);
		if (!db::isError($mi) && !db::isError($t)) {
			if (($mi->getAreaID() == $t->getAVAreaID() || $mi->getAreaID() == $t->getPhotoAreaID()) && $t->isActive()) {
				$view = 'media';
				$media = new SectionTemplate;
				$media->file = "media_detail.php";
				$media->args['media'] = $mi;
				$media->args['exitURL'] = (USE_MOD_REWRITE) ? '/tour/' . $t->getID() . '/' : '/tours.php?id=' . $t->getID();
			}
		}
	} else {
		$view = 'detail';		
		$tour = new SectionTemplate;
		$tour->file = "tour_detail.php";
		$tour->args['tour'] = $t;
		if (USE_MOD_REWRITE) {
			$auxLink = '<a href="' . SITE_WEB_DIRECTORY . '/tours/">Return to Tour List</a>';
		} else {
			$auxLink = '<a href="' . SITE_WEB_DIRECTORY . '/tours.php">Return to Tour List</a>';
		}
	}
}
if ($view != 'media' && $view != 'detail') {
	$view = 'list';
	$sl = new TourList();
	$result = $sl->get_tours(9999,0,1);
	$tours = array();
	foreach ($result as $t) {
		$detail = new SectionTemplate;
		$detail->file = "tour_summary.php";
		$detail->args['tour'] = $t;
		$tours[] = $detail;
	}
	if (count($tours) == 0) {
		unset($tours);
	}
}

